import {Request, Response} from 'express';
import {z} from 'zod';
import botService from '@/service/bot';

class BotController {
    async summaryContentWithStream(req: Request, res: Response) {
        const {content} = z.object({content: z.string()}).parse(req.body);
        const stream = await botService.summaryContentWithStream(content);

        res.setHeader('Content-Type', 'text/event-stream');
        const rd = stream.getReader();
        const push = async () => {
            const {done, value} = await rd.read();
            if (done) return res.end();
            res.write(value);
            push();
        };
        push();
    }
}

export const botController = new BotController();
